package com.ptswitch.material.util.security;

import java.util.List;

import org.hxzon.tapestry5.model.TreeModel;

import com.ptswitch.material.model.security.Permission;

public class PermissionTreeUtil {

    public static final TreeModel<Permission> permissionTreeModel = new TreeModel<Permission>() {

        @Override
        public boolean isLeaf(Permission value) {
            return value.getChildren().isEmpty();
        }

        @Override
        public boolean hasChildren(Permission value) {
            return !value.getChildren().isEmpty();
        }

        @Override
        public List<Permission> getChildren(Permission value) {
            return value.getChildren();
        }

        @Override
        public String getLabel(Permission value) {
            return value.getDisplayName();
        }

        @Override
        public Permission getRoot() {
            return PermissionUtil.All;
        }

    };

}
